package com.ihemou.system.controller;

import com.ihemou.common.core.utils.poi.ExcelUtil;
import com.ihemou.common.core.web.controller.BaseController;
import com.ihemou.common.core.web.domain.AjaxResult;
import com.ihemou.common.core.web.page.TableDataInfo;
import com.ihemou.common.log.annotation.Log;
import com.ihemou.common.log.enums.BusinessType;
import com.ihemou.common.security.annotation.PreAuthorize;
import com.ihemou.system.domain.SysUserSocialApp;
import com.ihemou.system.service.ISysUserSocialAppService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * All rights Reserved, Designed By saperliu
 * Copyright:    Copyright(C) 2021-2021
 *
 * @author saperliu
 * @version 1.0.0
 * @date 2021年09月02日
 * @Description 应用所属用户的接口
 */
@Slf4j
@RestController
public class SysUserSocialAppController extends BaseController {

    @Autowired
    private ISysUserSocialAppService sysUserSocialAppService;

    /**
     * 查询应用所属用户列表
     */
    @PreAuthorize(hasPermi = "social:sysUserSocialApp:list")
    @GetMapping("/back/social/sysUserSocialApp/list")
    public TableDataInfo list(SysUserSocialApp sysUserSocialApp) {
        startPage();
        List<SysUserSocialApp> list = sysUserSocialAppService.findSysUserSocialAppByCondition(sysUserSocialApp);
        return getDataTable(list);
    }

    /**
     * 导出应用所属用户列表
     */
    @PreAuthorize(hasPermi = "social:sysUserSocialApp:export")
    @Log(title = "应用所属用户", businessType = BusinessType.EXPORT)
    @PostMapping("/back/social/sysUserSocialApp/export")
    public void export(HttpServletResponse response, SysUserSocialApp sysUserSocialApp) throws IOException {
        List<SysUserSocialApp> list = sysUserSocialAppService.findSysUserSocialAppByCondition(sysUserSocialApp);
        ExcelUtil<SysUserSocialApp> util = new ExcelUtil<SysUserSocialApp>(SysUserSocialApp.class);
        util.exportExcel(response, list, "应用所属用户数据");
    }

    /**
     * 获取应用所属用户详细信息
     */
    @PreAuthorize(hasPermi = "social:sysUserSocialApp:query")
    @GetMapping(value = "/back/social/sysUserSocialApp/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(sysUserSocialAppService.selectSysUserSocialAppById(id));
    }

    /**
     * 新增应用所属用户
     */
    @PreAuthorize(hasPermi = "social:sysUserSocialApp:add")
    @Log(title = "应用所属用户", businessType = BusinessType.INSERT)
    @PostMapping("/back/social/sysUserSocialApp/save")
    public AjaxResult add(@RequestBody SysUserSocialApp sysUserSocialApp) {
        return toAjax(sysUserSocialAppService.insertSysUserSocialApp(sysUserSocialApp));
    }

    /**
     * 修改应用所属用户
     */
    @PreAuthorize(hasPermi = "social:sysUserSocialApp:edit")
    @Log(title = "应用所属用户", businessType = BusinessType.UPDATE)
    @PutMapping("/back/social/sysUserSocialApp/update")
    public AjaxResult edit(@RequestBody SysUserSocialApp sysUserSocialApp) {
        return toAjax(sysUserSocialAppService.updateSysUserSocialApp(sysUserSocialApp));
    }

    /**
     * 删除应用所属用户
     */
    @PreAuthorize(hasPermi = "social:sysUserSocialApp:remove")
    @Log(title = "应用所属用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/back/social/sysUserSocialApp/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysUserSocialAppService.deleteSysUserSocialAppByIds(ids));
    }
}
